let domWidth = window.screen.availWidth //获取屏幕可使用宽度的数值
let gridWidth = domWidth*0.92   // 棋盘格的宽度
let cellLength = domWidth*0.18   // 每个格子的边长
let cellSpace = domWidth*0.04   // 间隙的长度

function getNumberBackgroundColor(number) {
    switch (number) {
        case 2:
            return "#eee4da";
            break;
        case 4:
            return "#ede0c8";
            break;
        case 8:
            return "#f2b179";
            break;
        case 16:
            return "#f59563";
            break;
        case 32:
            return "#f67c5f";
            break;
        case 64:
            return "#f65e3b";
            break;
        case 128:
            return "#edcf72";
            break;
        case 256:
            return "#edcc61";
            break;
        case 512:
            return "#9c0";
            break;
        case 1024:
            return "#33b5e5";
            break;
        case 2048:
            return "#a6c";
            break;
        case 4096:
            return "#93c";
            break;
        default:
            return "block";
    }
}

function getNumberColor(number) {
    if (number <= 4) {
        return '#776e65'
    }
    return "white"
}

function getPosTop(i,j){
    return i * (cellSpace+cellLength) + cellSpace
}

function getPosLeft(i,j){
    return j * (cellSpace+cellLength) + cellSpace
}

function nospace(board) {
    for (let i = 0; i < rows; i++) {
        for (let j = 0; j < cols; j++) {
            if (board[i][j] === 0) {
                return true
            }
        }
    }
    return false
}

function canMoveLeft(board) {
    for (let i = 0; i < rows; i++) {
        for (let j = 1; j < cols; j++) {
            if (board[i][j] != 0) {
                if (board[i][j - 1] === 0 || board[i][j - 1] === board[i][j]) {
                    return true
                }
            }
        }
    }
    return false
}

function canMoveUp(board) {
    for (let i = 1; i < rows; i++) {
        for (let j = 0; j < cols; j++) {
            if (board[i][j] != 0) {
                if (board[i-1][j] === 0 || board[i-1][j] === board[i][j]) {
                    return true
                }
            }
        }
    }
    return false
}

function canMoveRight(board) {
    for (let i = 0; i < rows; i++) {
        for (let j = cols-2; j >=0; j--) {
            if (board[i][j] != 0) {
                if (board[i][j + 1] === 0 || board[i][j + 1] === board[i][j]) {
                    return true
                }
            }
        }
    }
    return false
}

function canMoveDown(board) {
    for (let i = rows-2; i >=0; i--) {
        for (let j = 0; j < cols; j++) {
            if (board[i][j] != 0) {
                if (board[i+1][j] === 0 || board[i+1][j] === board[i][j]) {
                    return true
                }
            }
        }
    }
    return false
}

// 判断水平移动中途会不会有障碍物
function noRoadblockLevel(row, col1, col2, board) {
    for (let i = col1 + 1; i < col2; i++) {
        if (board[row][i] !== 0) {
            // 中间有障碍物
            return false
        }
    }
    return true
}

// 判断垂直移动中途会不会有障碍物
function noRoadblockVertical(col, row1, row2, board) {
    for (let i = row1 + 1; i < row2; i++) {
        if (board[i][col] !== 0) {
            // 中间有障碍物
            return false
        }
    }
    return true
}

function nomove(board){
    if(canMoveLeft(board)||canMoveRight(board)||canMoveUp(board)||canMoveDown(board)){
        return false
    }
    return true
}

